package com.itheima.web.manager;

import com.itheima.domain.mongo.Movement;
import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Component
public class MovementManager {

    @DubboReference
    private MovementService movementService;
    public ResponseEntity passMovement(String[] item,Integer state,String message) {

        Map<String,String> map = new HashMap<>();
        for (String ids : item) {
            //通过rpc查询movement
            Movement movement = movementService.findById(new ObjectId(ids));
            //修改状态
            movement.setState(state);
            //修改
            movementService.updateState(movement);
        }

        map.put("message",message);
        return ResponseEntity.ok(map);
    }
}
